<template>
  <footer>
    <ul>
      <!-- <li
        v-for="(item, index) in footerList"
        :key="item.title"
        :class="{ active: activeIndex === index }"
        @click="tabChange(item, index)"
      >
        <span class="iconfont" :class="item.icon"></span>
        <p>{{ item.title }}</p>
      </li> -->
      <router-link
        v-for="item in footerList"
        :key="item.title"
        :to="'/home' + item.url"
        tag="li"
      >
        <span class="iconfont" :class="item.icon"></span>
        <p>{{ item.title }}</p>
      </router-link>
    </ul>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      footerList: [
        {
          title: "电影/影院",
          icon: "icon-dianying",
          url: "/movies",
        },
        {
          title: "视频",
          icon: "icon-shipin1",
          url: "/video",
        },
        {
          title: "小视频",
          icon: "icon-shipin",
          url: "/mini",
        },
        {
          title: "演出",
          icon: "icon-yanchu-xianxing2-0",
          url: "/show",
        },
        {
          title: "我的",
          icon: "icon-wode",
          url: "/mine",
        },
      ],
      // sessionStorage取得值有可能不存在
      // 取出来的值是字符串，需要转成数字
      // activeIndex: +sessionStorage.getItem("factive") || 0,
    };
  },
  methods: {
    tabChange(item, index) {
      // 切换高亮
      this.activeIndex = index;
      // 将index存入本地存储
      sessionStorage.setItem("factive", index);
      // 条状
      this.$router.push("/home" + item.url);
    },
  },
  // watch: {
  //   $route(to) {
  //     console.log(to.path);
  //   },
  // },
};
</script>

<style lang="less" scoped>
footer {
  width: 100%;
  height: 48px;
  background: #fff;
  border-top: 1px solid @border-color;
  position: fixed;
  left: 0;
  bottom: 0;

  ul {
    width: 100%;
    height: 100%;
    display: flex;

    li {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-size: @xs-font;

      .iconfont {
        font-size: @xxl-font;
      }
    }
  }
}

.router-link-active {
  color: @theme-color;
}
</style>
